Allow and start using C99 declaration-after-statement
authorColin Walters <walters@verbum.org>
Fri, 3 Mar 2017 17:10:46 +0000 (12:10 -0500)
committerAtomic Bot <atomic-devel@projectatomic.io>
Mon, 6 Mar 2017 18:33:50 +0000 (18:33 +0000)
I've seen code in a few places that I think on balance is definitely better this
way.  Some of our functions have huge variable declaration sections.
This change includes one small example where we could start using declarations
after statements.

A concern I had was - how does this interact with `__attribute__((cleanup))` and
early returns? I tested it, and AFAICS the behavior is what you'd expect - the
cleanup function isn't called if its variable isn't reachable.

Closes: #718
Approved by: jlebon

configure.ac
src/libostree/ostree-repo.c

index 83b8f48ff5a66f031230c7a3d924a87ed854e7e9..7fac081be3644da142436047a1afe830b19750a6 100644 (file)
@@ -33,7 +33,6 @@ CC_CHECK_FLAGS_APPEND([WARN_CFLAGS], [CFLAGS], [\
         -Werror=incompatible-pointer-types \
         -Werror=misleading-indentation \
        -Werror=missing-include-dirs -Werror=aggregate-return \
-       -Werror=declaration-after-statement \
 ])
 AC_SUBST(WARN_CFLAGS)
 
index dc0eb57512073af3521a19ee0e1e379f95550706..716044808bfc8acaa59159bc790fd0aabd4a9f69 100644 (file)
@@ -4309,16 +4309,14 @@ find_keyring (OstreeRepo          *self,
               OstreeRemote        *remote,
               GCancellable        *cancellable)
 {
-  g_autoptr(GFile) remotes_d = NULL;
-  g_autoptr(GFile) file = NULL;
-  file = g_file_get_child (self->repodir, remote->keyring);
+  g_autoptr(GFile) file = g_file_get_child (self->repodir, remote->keyring);
 
   if (g_file_query_exists (file, cancellable))
     {
       return g_steal_pointer (&file);
     }
 
-  remotes_d = get_remotes_d_dir (self);
+  g_autoptr(GFile) remotes_d = get_remotes_d_dir (self);
   if (remotes_d)
     {
       g_autoptr(GFile) file2 = g_file_get_child (remotes_d, remote->keyring);